
CC=gcc
CFLAG= -g
AR=ar
EXEC=radclient
SRC=utils.c server.c output.c queue.c radclient.c 
OBJECT=$(SRC:.c=.o)
LIB=libradius.a
INCLUDE=-I./include
INC=radclient.h output.h config.h utils.h
PREFIX=./release
ISLINUX = $(shell uname | grep -i linux)

ifeq ($(ISLINUX), )
	LDFLAG= -lpthread -lm -lcurses -lsocket -L$(LIB:lib%.a=%) -l$(LIB:lib%.a=%)
else
	LDFLAG= -lpthread -lm -lncurses -L$(LIB:lib%.a=%) -l$(LIB:lib%.a=%)
endif


.PHONY: clean all

export
unexport $(INCLUDE) $(OBJECT)

all:$(EXEC)

%.o : %.c $(INC)
	$(CC) $(CFLAG) $(INCLUDE) -c $<

lib%.a :
	cd $(@:lib%.a=%) && $(MAKE)

$(EXEC) : $(OBJECT)  $(LIB)
	$(CC) -o $(EXEC) $(CFLAG) $(OBJECT) $(LDFLAG)

lib$(LIBradius).a:
	cd $(LIBradiusDIR) && $(MAKE)

clean_%:
	cd $(@:clean_%=%) && make clean

clean : $(LIB:lib%.a=clean_%) 
	rm *.o $(EXEC)

install:
	mv $(EXEC) ./release
